<template>
  <j-modal :title="title" :width="700" :visible="visible" switchFullscreen @cancel="handleCancel" @ok="handleOk"
    :cancelButtonProps="footerBtnProps" :okButtonProps="footerBtnProps">
    <a-form-model ref="form" :model="form" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }" :rules="formRules">
      <a-row :gutter="30">
        <a-col :span="12">
          <a-form-model-item label="姓名：" prop="lawyerName">
            <a-input v-model="form.lawyerName" placeholder="请输入" :disabled="disabled" />
          </a-form-model-item>
          <a-form-model-item label="联系电话：" prop="lawyerPhone">
            <a-input-number style="width: 100%;" :min="0" :step="1" v-model="form.lawyerPhone" placeholder="请输入" :disabled="disabled" />
          </a-form-model-item>

          <a-form-model-item label="擅长领域：" prop="businessArea">
            
            <a-select v-model="form.businessArea" mode="multiple" :disabled="disabled">
              <a-select-option v-for="(item, index) in areaSelect" :key="index" :value="item.value">{{item.label}}</a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :span="12">
          <j-image-upload v-model="form.picture" :disabled="disabled" bizPath="scott/pic" :isMultiple="false" />
        </a-col>
      </a-row>

      <a-form-model-item label="简介：" :label-col="{ span: 4 }" :wrapper-col="{ span: 16 }" prop="lawyerIntroduce">
        <a-textarea v-model="form.lawyerIntroduce" placeholder="请输入" :auto-size="{ minRows: 2, maxRows: 5 }"
          :disabled="disabled" />
      </a-form-model-item>
    </a-form-model>
  </j-modal>
</template>
<script>
  import {
    addLawyer
  } from '@/api/sjsk/legalAid/organize'
  export default {
    name: 'LawyerModal',
    props: {
      disabled: {
        type: Boolean,
        default: false
      }
    },
    computed: {
      footerBtnProps: function() {
        return {
          style: {
            display: this.disabled ? 'none' : 'inline-block'
          }
        }
      }
    },
    data() {
      return {
        title: '新增机构',
        visible: false,
        areaOptions: [],
        areaSelect: [
          {
            label: '合同纠纷',
            value: '1'
          },
          {
            label: '公司事务',
            value: '2'
          },
          {
            label: '刑事案件',
            value: '3'
          },
          {
            label: '债权纠纷',
            value: '4'
          },
          {
            label: '医疗纠纷',
            value: '5'
          },
          {
            label: '婚姻继承',
            value: '6'
          },
          {
            label: '劳动纠纷',
            value: '7'
          },
          {
            label: '知识产权',
            value: '8'
          },
          {
            label: '侵权纠纷',
            value: '9'
          },
          {
            label: '涉外纠纷',
            value: '10'
          },
          {
            label: '金融证券',
            value: '11'
          },
          {
            label: '拆迁安置',
            value: '12'
          },
          {
            label: '房产土地',
            value: '13'
          },
          {
            label: '工程建筑',
            value: '14'
          },
          {
            label: '物权纠纷',
            value: '15'
          },
          {
            label: '损害赔偿',
            value: '16'
          },
          {
            label: '国际事务',
            value: '17'
          },
          
          
          
          
          
          {
            label: '行政案件',
            value: '18'
          },
          {
            label: '工伤维权',
            value: '19'
          },
          {
            label: '公益法律',
            value: '20'
          }
        ],
        form: {
          "businessArea": [],
          "lawFirmId": '',
          "lawFirmName": "",
          "lawyerIntroduce": "",
          "lawyerName": "",
          "lawyerPhone": "",
          "picture": "",
        },
        formRules: {
          lawyerName: {
            required: true,
            message: '请输入',
            trigger: ['blur']
          },
          businessArea: {
            required: true,
            type: 'array',
            message: '请输入',
            trigger: ['blur']
          },
          lawyerPhone: {
            required: true,
            message: '请输入',
            trigger: ['blur']
          },
          lawyerIntroduce: {
            required: true,
            message: '请输入',
            trigger: ['blur']
          },
        }
      }
    },
    methods: {
      
      show(data, lawFirmId) {
        this.visible = true
        if (data) {
          this.title = '编辑律师'
          const form = JSON.parse(JSON.stringify(data))
          form.businessArea = form.businessArea.split(',')
          this.form = form
        } else {
          this.title = '新增律师'
          this.form = {
            "businessArea": [],
            "lawFirmId": '',
            "lawFirmName": "",
            "lawyerIntroduce": "",
            "lawyerName": "",
            "lawyerPhone": "",
            "picture": "",
          }
          this.form.lawFirmId = lawFirmId
        }
        if (this.disabled) {
          this.title = '律师详情'
        }
      },
      handleCancel() {
        this.visible = false
      },
      handleOk() {
        this.$refs.form.validate().then(res => {
          const form = JSON.parse(JSON.stringify(this.form))
          form.businessArea = form.businessArea.toString()
          addLawyer(form).then(res => {
            const {
              success,
              message
            } = res
            if (success) {
              this.visible = false
              this.$message.success('添加成功！')
              this.$emit('success')
            } else {
              this.$message.error(message)
            }
          })
        })

      }
    },
  }
</script>
<style lang="less" scoped>
  /deep/.ant-form-item {
    margin-bottom: 10px;
  }
  /deep/.ant-input-number-handler-wrap {
    //   display: none;
  }

</style>
